package com.example.administrator.szb.fragments.fragment_forTab.home.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.szb.R;
import com.example.administrator.szb.fragments.fragment_forTab.home.bean.LuYanList;

import java.util.List;

/**
 * Created by stone on 2018/1/19.
 */

public class LuYanadapter extends BaseAdapter {
    private Context context;
    private List list;
    LayoutInflater inflater;
    public LuYanadapter(Context context, List list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public  Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = inflater.inflate(R.layout.item_luyan,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        LuYanList luYanList = (LuYanList) getItem(position);
        holder.title.setText(luYanList.getTitle());
        holder.comyany.setText(luYanList.getCompany_name());
        holder.tv_type.setText(luYanList.getType_name());
        String[] timestart = luYanList.getStart_time().split(" ");
        String[] timeend = luYanList.getEnd_time().split(" ");
        holder.tv_time_start.setText(timestart[0]);
        holder.tv_time_end.setText(timeend[0]);
        switch (luYanList.getStatus()){
            case 0:
                holder.tv_status.setBackgroundColor(Color.parseColor("#FFD1D1"));
                holder.tv_status.setTextColor(Color.parseColor("#FF4040"));
                holder.tv_status.setText("待审核");
                break;
            case 1:
                holder.tv_status.setBackgroundColor(Color.parseColor("#FFD1D1"));
                holder.tv_status.setTextColor(Color.parseColor("#FF4040"));
                holder.tv_status.setText("报名中");

                break;
            case 2:
                holder.tv_status.setBackgroundColor(Color.parseColor("#A2A8B6"));
                holder.tv_status.setTextColor(Color.parseColor("#FFFFFF"));
                holder.tv_status.setText("未通过");

                break;
            case 3:
                holder.tv_status.setBackgroundColor(Color.parseColor("#A2A8B6"));
                holder.tv_status.setTextColor(Color.parseColor("#FFFFFF"));
                holder.tv_status.setText("已结束");

                break;
        }

        return convertView;
    }

    class ViewHolder{
         TextView title;
         TextView tv_status;
         TextView comyany;
         TextView tv_type;
         TextView tv_time_start;
         TextView tv_time_end;
        public ViewHolder(View view){
            title = (TextView) view.findViewById(R.id.title);
            tv_status = (TextView) view.findViewById(R.id.tv_status);
            comyany = (TextView) view.findViewById(R.id.comyany);
            tv_type = (TextView) view.findViewById(R.id.tv_type);
            tv_time_start = (TextView) view.findViewById(R.id.tv_time_start);
            tv_time_end = (TextView) view.findViewById(R.id.tv_time_end);
        }
    }
}
